package com.practice.book.enums;

import lombok.Data;
import lombok.Getter;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-01-21
 * Time: 16:08
 */
@Getter
public enum BookStatusEnum {
    DELETE(0,"删除"),
    NORMAL(1,"可借阅"),
    FORBIDDEN(2,"不可借阅");

    private Integer code;
    private String desc;

    BookStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static BookStatusEnum getStatusByCode(Integer code) {
        //1.第一种方法使用if else
        /*if(code == 0) {
            return BookStatusEnum.DELETE;
        }else if(code ==1 ) {
            ....
        }*/

        //2.使用switch case
        /*switch(code) {
            case 0:
                return BookStatusEnum.DELETE;
                break;
            case 1: return BookStatusEnum.NORMAL;
            break;
            ...
        }*/

        //3.用lambda表达式
        return Arrays.stream(BookStatusEnum.values()).filter(x -> x.getCode() == code).findFirst().get();
    }
}
